package tst

import java.nio.channels.*
import java.nio.file.StandardOpenOption

def path = 'c:/temp/locked.txt'
FileChannel channel = FileChannel.open(new File(path).toPath(),StandardOpenOption.CREATE,StandardOpenOption.WRITE);
//阻塞直至可获得锁。
FileLock lock = channel.lock();


lock.close();